from django.core.management.base import BaseCommand
from apps.oaauth.models import OAUser, OADepartment


class Command(BaseCommand):
    def handle(self, *args, **options):
        ## 获取的 user 信息
        boarder = OADepartment.objects.get(name="董事会")
        developer = OADepartment.objects.get(name="产品研发部门")
        operator = OADepartment.objects.get(name="运营部")
        saler = OADepartment.objects.get(name="销售部")
        hr = OADepartment.objects.get(name="人事部")
        finance = OADepartment.objects.get(name="财务部")



        ##1、东东 属于董事会的 leader
        dongdong = OAUser.objects.create_superuser(email="dongdong@gmail.com",realname="东东",password="admin",department=boarder)
        ##2、多多 属于董事会的 leader
        duoduo = OAUser.objects.create_superuser(email="duoduo@gmail.com",realname="多多",password="admin",department=boarder)
        ##3、张三 产品研发部
        zhangsan = OAUser.objects.create_user(email="zhangsan@gmail.com",realname="张三",password="admin",department=developer)
        ##4、李四 运营部 leader
        lisi = OAUser.objects.create_user(email="lisi@gmail.com",realname="李四",password="admin",department=operator)
        ##5、王五 人事部的leader
        wangwu = OAUser.objects.create_user(email="wangwu@gmail.com",realname="王五",password="admin",department=hr)
        ##6、赵六 财务部 leader
        zhaoliu = OAUser.objects.create_user(email="zhaoliu@gmail.com",realname="赵六",password="admin",department=finance)
        ##7、孙七 销售部 leader
        sunqi = OAUser.objects.create_user(email="sunqi@gmail.com",realname="孙七",password="admin",department=saler)

        ## 创建 department 和 USER 对应的关系
        boarder.leader = dongdong
        boarder.manager = None

        developer.leader = zhangsan
        developer.manager = dongdong

        operator.leader = lisi
        operator.manager = dongdong

        hr.leader = wangwu
        hr.manager = duoduo

        finance.leader = zhaoliu
        finance.manager = duoduo

        saler.leader = sunqi
        saler.manager = duoduo

        boarder.save()
        developer.save()
        operator.save()
        hr.save()
        finance.save()
        saler.save()

        self.stdout.write("部门数据初始化成功")



